
package dao;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import conectaBD.CriaConexao;
import java.sql.SQLException;
import negocios.Locacao;


public class LocacaoDAO {
   private Connection conexao;

    public LocacaoDAO() throws SQLException {
        this.conexao = (Connection) CriaConexao.getConexao();
    } 
     public void adicionar(Locacao a) {
        try {
            String sql = "insert into locacao (id_aluno,id_livro,data_saida,data_devolucao) values (?, ?, ?, ?)";
            PreparedStatement stmt = (PreparedStatement) conexao.prepareStatement(sql);
            stmt.setInt(1, a.id_aluno);
            stmt.setInt(2, a.id_livro);
            stmt.setString(3, a.data_saida);
            stmt.setString(4, a.data_devolucao);
            stmt.execute();
            stmt.close();
        } catch (SQLException ex) {
            System.out.println("Erro" + ex.getMessage());
        }
    }
}
